package csel.controller.commandutil;

import java.util.concurrent.ConcurrentHashMap;

import csel.controller.enums.CommandEnum;
import csel.model.GameCommand;

public class CommandPool
{
	private final ConcurrentHashMap<CommandEnum, CommandFactory> commandMap;
	private static CommandPool instance;

	public CommandPool()
	{
		commandMap = new ConcurrentHashMap<CommandEnum, CommandFactory>();
	}

	public static CommandPool getInstance()
	{
		if (instance == null)
		{
			instance = new CommandPool();
		}
		return instance;
	}

	public void addCommandFactory(CommandEnum commandEnum,
			CommandFactory commandFactory)
	{
		commandMap.put(commandEnum, commandFactory);
	}

	public GameCommand getCommand(CommandEnum commandEnum,
			Parameterizer parameterizer)
	{
		CommandFactory commandFactory = commandMap.get(commandEnum);
		return commandFactory.getNewCommand(parameterizer);
	}
}
